/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package domain;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.*;

/**
 *
 * @author Evgeny
 */
@Entity
public class Reference  {

   
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    private String title;
    private String rYear;
    private String edition;
    @ManyToOne
    private Publisher publisher = null;
    private String city;
    private String doi;
    private String isbn10;
    private String isbn13;
    private String eisbn13; 
    @ManyToMany(mappedBy="reference")
    private Set<Author> authors;
    @ManyToMany(mappedBy="Treference")
    private Set<Translator> translators;
    private String type;
    private String pages;
    private String volume;
    private String issue;
    private String address;
    private String Rdate;
    private String other;
    private String Wlanguage;
    private String subject;
    
    public void deletePub()
        {
            publisher = null;
        }

    public Reference(String title, String rYear, String edition, String city, String doi, String isbn10, String isbn13, String eisbn13, String type, String pages, String volume, String issue, String address, String date, String other, String language, String subject) {
        this.title = title;
        this.rYear = rYear;
        this.edition = edition;
        this.city = city;
        this.doi = doi;
        this.isbn10 = isbn10;
        this.isbn13 = isbn13;
        this.eisbn13 = eisbn13;
        this.type = type;
        this.volume = volume;
        this.issue = issue;
        this.address = address;
        this.Rdate = date;
        this.other = other;
        this.Wlanguage = language;
        this.subject = subject;
        authors = new HashSet<Author>();
        //translators = new HashSet<Author>();
    }

    public Reference() {
    }

    public int getId() {
        return id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getrYear() {
        return rYear;
    }

    public void setrYear(String rYear) {
        this.rYear = rYear;
    }

    public String getEdition() {
        return edition;
    }

    public void setEdition(String edition) {
        this.edition = edition;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getDoi() {
        return doi;
    }

    public void setDoi(String doi) {
        this.doi = doi;
    }

    public String getIsbn10() {
        return isbn10;
    }

    public void setIsbn10(String isbn10) {
        this.isbn10 = isbn10;
    }

    public String getIsbn13() {
        return isbn13;
    }

    public void setIsbn13(String isbn13) {
        this.isbn13 = isbn13;
    }

    public String getEisbn13() {
        return eisbn13;
    }

    public void setEisbn13(String eisbn13) {
        this.eisbn13 = eisbn13;
    }

    public Set<Author> getAuthors() {
        return authors;
    }

    public void setAuthors(Set<Author> authors) {
        this.authors = authors;
    }

    public void addAuthor(Author author) {
        if (!getAuthors().contains(author)) {
            getAuthors().add(author);
        }
        if (!author.getReference().contains(this)) {
            author.getReference().add(this);
        }
    }

    public Set<Translator> getTranslators() {
        return translators;
    }

    public void setTranslators(Set<Translator> translators) {
        this.translators = translators;
    }
    
    public void addTranslator(Translator Tauthor) {
        if (!getTranslators().contains(Tauthor)) {
            getTranslators().add(Tauthor);
        }
        if (!Tauthor.getTreference().contains(this)) {
            Tauthor.getTreference().add(this);
        } 
    }
    
    public void deleteTranslator(int id)
        {
                for (Translator aa:translators)
            {
                if (aa.getId()==id)
                    translators.remove(aa);
            }
        }
    
    public void deleteAuthor(int id)
        {
                for (Author aa:authors)
            {
                if (aa.getId()==id)
                    authors.remove(aa);
            }
        }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getPages() {
        return pages;
    }

    public void setPages(String startPage) {
        this.pages = startPage;
    }


    public String getVolume() {
        return volume;
    }

    public void setVolume(String volume) {
        this.volume = volume;
    }

    public String getIssue() {
        return issue;
    }

    public void setIssue(String issue) {
        this.issue = issue;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getDate() {
        return Rdate;
    }

    public void setDate(String date) {
        this.Rdate = date;
    }

    public String getOther() {
        return other;
    }

    public void setOther(String other) {
        this.other = other;
    }

    public String getLanguage() {
        return Wlanguage;
    }

    public void setLanguage(String language) {
        this.Wlanguage = language;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    /*public void addAuthor(Author auth) {
        this.authors.add(auth);
    }

    public void addTranslator(Author auth) { 
        this.translators.add(auth);
    }*/

    public void setId(int id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "domain.Reference[ id=" + id + " ]";
    }
    
    public Publisher getPublisher() {
        return publisher;
    }

    public void setPublisher(Publisher publisher) {
        this.publisher = publisher;
    }

    public String getRdate() {
        return Rdate;
    }

    public void setRdate(String Rdate) {
        this.Rdate = Rdate;
    }

    public String getWlanguage() {
        return Wlanguage;
    }

    public void setWlanguage(String Wlanguage) {
        this.Wlanguage = Wlanguage;
    }
}
